#ifndef RISING_STAR_SERVICES_H
#define RISING_STAR_SERVICES_H

#include "Config.h"

using namespace boost::asio;
using namespace boost;

namespace RisingStar
{
	
	class CTask
	{
		public:
		CTask():ioServicePtr(new asio::io_service),
				workPtr(new io_service::work(*ioServicePtr)),
				threadPtr(new boost::thread(bind(&asio::io_service::run, ioServicePtr)))
		{
			
		};
		
		~CTask()
		{
			
		};
		
		IOServicePtr ioServicePtr;
		WorkPtr		workPtr;
		ThreadPtr	threadPtr;
		
	};
	
	class CServices: public boost::noncopyable
	{
	

	private:

		size_t				mMaxServiceCount;
		size_t				mMinServiceCount;
		
		
		vector<CTask> mServices;
		vector<CTask> mServicesUsed;
	//	vector<IOServicePtr> mIOServices;
	//	vector<IOServicePtr> mIOServicesUsed;
		
	//	vector<WorkPtr> mWorks;
	//	vector<ThreadPtr> mThreads; 
		
		boost::mutex mMutex;

		bool AddService();
	public:	

		explicit CServices(size_t poolSize,size_t maxPoolSize);
		~CServices();
		
		bool Start();
		bool Stop();
		bool Join();
		size_t GetFreeServiceCount();//获取服务数
		IOServicePtr& GetServicePtr();
		
		//获取空闲的Service的索引值;
		bool ProcessFreeService();

		
	};
	

}

#endif
